package com.ruibang.glass.material.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.constant.Constants;
import com.ruibang.glass.material.domain.req.ContainerTransferRecordReq;
import com.ruibang.glass.material.entity.ContainerTransferRecord;
import com.ruibang.glass.material.mapper.ContainerTransferRecordMapper;
import com.ruibang.glass.material.service.ContainerTransferRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 容器位置转移记录 服务实现类
 * </p>
 *
 * @author songJinKang
 * @since 2024-03-25
 */
@Slf4j
@Service
public class ContainerTransferRecordServiceImpl extends ServiceImpl<ContainerTransferRecordMapper, ContainerTransferRecord> implements ContainerTransferRecordService {

    @Override
    public IPage<ContainerTransferRecord> pageQuery(ContainerTransferRecordReq containerTransferRecordReq) {
        QueryWrapper<ContainerTransferRecord> qw = new QueryWrapper<>();
        qw.lambda().eq(ContainerTransferRecord::getIsDelete, Constants.ZERO_STR);
        qw.lambda().like(StringUtils.isNotBlank(containerTransferRecordReq.getContainerCode()), ContainerTransferRecord::getContainerCode, containerTransferRecordReq.getContainerCode());
        qw.lambda().eq(StringUtils.isNotBlank(containerTransferRecordReq.getContainerType()), ContainerTransferRecord::getContainerType, containerTransferRecordReq.getContainerType());
        qw.lambda().eq(StringUtils.isNotBlank(containerTransferRecordReq.getStatusId()), ContainerTransferRecord::getStatusId, containerTransferRecordReq.getStatusId());
        qw.lambda().eq(StringUtils.isNotBlank(containerTransferRecordReq.getWarehouseId()), ContainerTransferRecord::getWarehouseId, containerTransferRecordReq.getWarehouseId());
        qw.lambda().eq(StringUtils.isNotBlank(containerTransferRecordReq.getWarehousePositionId()), ContainerTransferRecord::getWarehousePositionId, containerTransferRecordReq.getWarehousePositionId());
        qw.lambda().like(StringUtils.isNotBlank(containerTransferRecordReq.getTransferUserName()), ContainerTransferRecord::getTransferUserName, containerTransferRecordReq.getTransferUserName());
        if (containerTransferRecordReq.getStartTime() != null && containerTransferRecordReq.getEndTime() != null) {
            qw.lambda().ge(ContainerTransferRecord::getTransferTime, containerTransferRecordReq.getStartTime());
            qw.lambda().le(ContainerTransferRecord::getTransferTime, containerTransferRecordReq.getEndTime());
        }
        qw.lambda().orderByDesc(ContainerTransferRecord::getCreateTime);
        return this.page(new Page<>(containerTransferRecordReq.getPageNo(), containerTransferRecordReq.getPageSize()), qw.lambda());
    }
}
